<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateEvent extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('event')) {
            return;
        }

        Schema::create('event', function (Blueprint $table) {
            $table->id();
            $table->string('event_number')->default('')->comment('事件编号');
            $table->string('type')->default('')->comment('事件类型');
            $table->unsignedInteger('customer_id')->default(0)->comment('客户ID');
            $table->unsignedInteger('customer_user_id')->default(0)->comment('客户联系人ID');
            $table->unsignedInteger('product_id')->default(0)->comment('关联商品ID');
            $table->string('contact_name')->default('')->comment('联系人姓名');
            $table->string('contact_telephone')->default('')->comment('联系人电话');
            $table->string('buy_channel')->default('')->comment('购买渠道');
            $table->string('buy_date')->default('')->comment('购买日期');
            $table->string('project_name')->default('')->comment('项目名称');
            $table->string('address')->default('')->comment('详细地址');
            $table->text('description')->comment('描述信息');
            $table->string('created_type')->default('')->comment('创建人类型(客户、客服)');
            $table->unsignedInteger('created_by')->default(0)->comment('创建人ID');
            $table->string('status')->default('')->comment('状态');
            $table->integer('create_time')->nullable();
            $table->integer('update_time')->nullable();
        });

        // 事件图片表
        Schema::create('event_image', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('event_id')->default(0)->comment('事件ID');
            $table->string('image')->default('')->comment('图片地址');
            $table->integer('create_time')->nullable();
            $table->integer('update_time')->nullable();
        });
        // 事件人员表
        Schema::create('event_user', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('event_id')->default(0);
            $table->unsignedInteger('user_id')->default(0)->comment('人员ID');
            $table->unsignedTinyInteger('is_master')->default(0)->comment('是否负责人');
            $table->integer('create_time')->nullable();
            $table->integer('update_time')->nullable();
        });
        // 事件状态历史表
        Schema::create('event_status_history', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('event_id')->default(0);
            $table->string('status')->comment('状态');
            $table->integer('create_time')->nullable();
            $table->integer('update_time')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('event');
    }
}
